﻿<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>用户帐户表单</title>
    <link href="/Themes/Styles/style.css" rel="stylesheet" />
    <script src="/Themes/Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/Validator/JValidator.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/artDialog/artDialog.source.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/artDialog/iframeTools.source.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/FunctionJS.js" type="text/javascript"></script>
    <script>
        $(document).ready(function () {
            LoadBindDrop();
            if (IsNullOrEmpty(GetQuery('key'))) {
                InitControl()
                CompanyClick("CompanyId");
                InitControl();
                DepartmentClick("DepartmentId");
                InitControl();
            }
        })
        //绑定下拉框，公司，部门，工作组，角色bigen
        var datajson = "";
        function LoadBindDrop() {
            //职称
            $("#TitleId").append("<option value=''>" + "==请选择==" + "</option>");
            //职位
            $("#DutyId").append("<option value=''>" + "==请选择==" + "</option>");
            var itemjson = "";
            getAjax("/User/InitBindDrop", "", function (data) {
                itemjson = eval("(" + data + ")");
                $.each(itemjson, function (i) {
                    if (itemjson[i].ItemsId == '2acba9e8-5fa7-4b6f-8ebd-56e753dd059a') {
                        $("#TitleId").append($("<option></option>").val(itemjson[i].ItemCode).html(itemjson[i].ItemName));
                    }
                    if (itemjson[i].ItemsId == '137a2d97-d1d9-4752-9c5e-239097e2ed68') {
                        $("#DutyId").append($("<option></option>").val(itemjson[i].ItemCode).html(itemjson[i].ItemName));
                    }
                });
            })


            $("#RoleId").append("<option value=''>" + "==请选择==" + "</option>");
            $("#CompanyId").append("<option value=''>" + "==请选择==" + "</option>");
            $("#DepartmentId").append("<option value=''>" + "==请选择==" + "</option>");
            $("#WorkgroupId").append("<option value=''>" + "==请选择==" + "</option>");
            getAjax("/Organize/LoadAction", "action=LoadBindDrop", function (data) {
                datajson = eval("(" + data + ")");
                $.each(datajson, function (i) {
                    if (datajson[i].Category == '公司') {
                        $("#CompanyId").append($("<option></option>").val(datajson[i].OrganizationId).html(datajson[i].FullName));
                    }
                });
            })
        }
        function CompanyClick(id) {
            $("#DepartmentId").empty();
            $("#DepartmentId").append("<option value=''>" + "==请选择==" + "</option>");
            InitRoles($('#' + id).val());
            $.each(datajson, function (i) {
                if (datajson[i].ParentId == $('#' + id).val()) {
                    $("#DepartmentId").append("<option value='" + datajson[i].OrganizationId + "'>" + datajson[i].FullName + "</option>");
                }
            });
        }
        function DepartmentClick(id) {
            $("#WorkgroupId").empty();
            $("#WorkgroupId").append("<option value=''>" + "==请选择==" + "</option>");
            $.each(datajson, function (i) {
                if (datajson[i].ParentId == $('#' + id).val()) {
                    $("#WorkgroupId").append("<option value='" + datajson[i].OrganizationId + "'>" + datajson[i].FullName + "</option>");
                }
            });
            if (IsNullOrEmpty(GetQuery('key'))) {
                var hiddenWorkgroupId = $("#hiddenWorkgroupId").val();
                
            }
        }
        //加载默认角色
        function InitRoles(OrganizationId) {
            $("#RoleId").empty();
            $("#RoleId").append("<option value=''>" + "==请选择==" + "</option>");
            getAjax('/Role/LoadAction', "action=InitRoles&OrganizationId=" + OrganizationId, function (data) {
                var json = eval("(" + data + ")");
                for (var i = 0; i < json.JSON.length; i++) {
                    var list = json.JSON[i];
                    $("#RoleId").append($("<option></option>").val(list.RoleId).html(list.FullName));
                }
            });
        }
        //保存事件
        function AcceptClick() {
            if (!CheckDataValid('#form1')) {
                return false;
            }
            var postData = GetWebControls("#form1");
            getAjax("/User/AcceptClick?key=" + GetQuery('key'), postData, function (data) {
                if (IsNullOrEmpty(GetQuery('key'))) {
                    if (data) { AlertCallback("恭喜您，更新成功。"); return false; }
                } else {
                    if (data) { AlertCallback("恭喜您，新增成功。"); return false; }
                }
                if (!data) {
                    Alert_Error("很抱歉，操作失败。"); return false;
                } else {
                    Alert_Wern(data); return false;
                }
            });
        }
        //得到一个对象实体
        function InitControl() {
            getAjax("/User/InitControl", { key: GetQuery('key') }, function (data) {
                var data = eval("(" + data + ")");
                SetWebControls(data);
                $("#Password").val("******");
                if (data.Birthday.length > 0) {
                    $("#Birthday").val(new Date(data.Birthday).pattern("yyyy-MM-dd"));
                }
            });
        }
    </script>
</head>
<body>
    <form id="form1" method="post">
        <table border="0" cellpadding="0" cellspacing="0" class="frm">
            <tr>
                <th>编号[<font face="宋体">*</font>]：
                </th>
                <td>
                    <input id="Code" name="Code" maxlength="50" type="text" class="txt" datacol="yes" err="编号" checkexpession="NotNull" style="width: 220px" />
                </td>
                <th>登录账户[<font face="宋体">*</font>]：
                </th>
                <td>
                    <input id="Account" name="Account" maxlength="50" type="text" class="txt" datacol="yes" err="登录账户" checkexpession="NotNull" style="width: 220px" />
                </td>
            </tr>
            <tr>
                <th>姓名[<font face="宋体">*</font>]：
                </th>
                <td>
                    <input id="RealName" name="RealName" maxlength="50" type="text" class="txt" datacol="yes" err="姓名" checkexpession="NotNull" style="width: 220px" />
                </td>
                <th>登录密码[<font face="宋体">*</font>]：
                </th>
                <td>
                    <input id="Password" name="Password" maxlength="50" type="password" class="txt" datacol="yes" err="登录密码" checkexpession="NotNull" style="width: 220px" />
                </td>
            </tr>
            <tr>
                <th>性别[<font face="宋体">*</font>]：
                </th>
                <td>
                    <select id="Gender" name="Gender" class="select" style="width: 227px">
                        <option value="男">男</option>
                        <option value="女">女</option>
                    </select>
                </td>
                <th>手机：</th>
                <td>
                    <input id="Mobile" name="Mobile" maxlength="11" type="text" class="txt" datacol="yes" err="手机" checkexpession="MobileOrNull" style="width: 220px" />
                </td>
            </tr>
            <tr>
                <th>出生日期：
                </th>
                <td>
                    <input id="Birthday" name="Birthday" maxlength="23" onfocus="WdatePicker()" type="text" class="txt" style="width: 220px" />
                </td>
                <th>电话：
                </th>
                <td>
                    <input id="Telephone" name="Telephone" maxlength="50" type="text" class="txt" datacol="yes" err="电话" checkexpession="PhoneOrNull" style="width: 220px" />
                </td>
            </tr>
            <tr>
                <th>职位：
                </th>
                <td>
                    <select id="DutyId" name="DutyId" class="select" style="width: 227px">
                    </select>
                </td>
                <th>QQ号码：
                </th>
                <td>
                    <input id="OICQ" name="OICQ" maxlength="50" type="text" class="txt" style="width: 220px" />
                </td>
            </tr>
            <tr>
                <th>职称：
                </th>
                <td>
                    <select id="TitleId" name="TitleId" class="select" style="width: 227px">
                    </select>
                </td>

                <th>电子邮件：
                </th>
                <td>
                    <input id="Email" name="Email" maxlength="50" type="text" class="txt" style="width: 220px" />
                </td>
            </tr>
            <tr>

                <th>公司[<font face="宋体">*</font>]：
                </th>
                <td>
                    <select id="CompanyId" name="CompanyId" onchange="CompanyClick(this.id)" datacol="yes" err="公司" checkexpession="NotNull" class="select" style="width: 227px">
                    </select>
                </td>
                <th>默认角色[<font face="宋体">*</font>]：
                </th>
                <td>
                    <select id="RoleId" name="RoleId" class="select" datacol="yes" err="默认角色" checkexpession="NotNull" style="width: 227px">
                    </select>
                </td>
            </tr>
            <tr>
                <th>部门名称<font face="宋体"></font>：
                </th>
                <td>
                    <select id="DepartmentId" name="DepartmentId" onchange="DepartmentClick(this.id)" datacol="yes" checkexpession="NotNull" err="部门名称" class="select" style="width: 227px">
                    </select>
                </td>
                <th>工作组名称：
                </th>
                <td>
                    <select id="WorkgroupId" name="WorkgroupId" class="select" style="width: 227px">
                    </select>
                </td>
            </tr>
            <tr>
                <th>有效性：
                </th>
                <td colspan="3">
                    <span class="item">
                        <input id="Enabled" name="Enabled" type="checkbox" checked="checked" style="vertical-align: middle;" />
                        <label for="Enabled" style="vertical-align: middle;">有效</label>
                        &nbsp;&nbsp;
                    </span>
                    <label style="vertical-align: middle; color: red;">注意：禁用该用户后，将不能登录。</label>
                </td>
            </tr>
            <tr>
                <th>说明：
                </th>
                <td colspan="3">
                    <textarea id="Description" name="Description" maxlength="200" class="txtArea" type="text" rows="7" style="width: 595px"></textarea>
                </td>
            </tr>
        </table>
        <div class="frmbottom">
            <a id="Accept" class="l-btn" href="javascript:void(0)" onclick="AcceptClick();"><span class="l-btn-left">
                <img src="/Themes/Images/16/accept.png" alt="" />确 认</span></a>

            <a class="l-btn" href="javascript:void(0)" onclick="OpenClose();"><span class="l-btn-left">
                <img src="/Themes/Images/16/cancel.png" alt="" />关 闭</span></a>
        </div>
    </form>
</body>
</html>
